package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.Consultant;
import com.sfzy.service.ConsultantService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("consultant")
public class ConsultantController {
    @Autowired
    private ConsultantService consultantService;
    //增加
    @PostMapping("add")
    public R insertConsultant(@RequestBody Consultant consultant) {
        int num = consultantService.insertConsultant(consultant);
        return R.ok(num);
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteConsultant(@PathVariable("id") int id) {
        int num = consultantService.deleteConsultant(id);
        return R.ok(num);
    }
    //修改
    @PutMapping("update")
    public R updateConsultant(@RequestBody Consultant consultant) {
        int num = consultantService.updateConsultant(consultant);
        return R.ok(num);
    }
    //根据id查询
    @GetMapping("{id}")
    public R getConsultantById(@PathVariable("id") int id) {
        Consultant consultant = consultantService.selectConsultantById3(id);
        return R.ok(consultant);
    }
    //分页查询
    @GetMapping("page3")
    public R getConsultants(Consultant consultant,
                            @RequestParam(required = false,defaultValue = "1")int pageNum,
                            @RequestParam(required = false,defaultValue = "3")int pageSize) {
        PageInfo<Consultant> consultantPageInfo = consultantService.selectConsultants3(consultant, pageNum, pageSize);
        return R.ok(consultantPageInfo);
    }
}
